package controller;

import util.ImageDb;
import model.ImageViewerModel;
import model.ImageViewerModelInterface;
import java.util.ArrayList;
import javax.swing.JFrame;
import view.GridView;

public class ImageViewerController implements ControllerInterface {    
    private ImageViewerModelInterface imv;
    private GridView view;
    
    public ImageViewerController (ImageViewerModelInterface model ){
        this.imv = model;
        view = new GridView(this, imv);
        view.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    	view.setLocation(0, 0);
    	view.setVisible(true);
    }        
    
    public void setModel(ImageViewerModel imv){
        this.imv = imv;
    }   
    
    public void insertImages(ArrayList<ImageDb> img)
    {
        imv.fillPicturesTable(img);        
    }
    
    public ArrayList<String> getImages()
    {
        return imv.queryPicturesTable();
    }
    
    public ArrayList<ImageDb> getFavorites()
    {
        return imv.getFavorites();
    }
    
    public ArrayList<ImageDb> query(ImageDb q)
    {
        return imv.requestImagesFromQuery(q);        
    }
    
    public void insertToFavorites(String img)
    {
        imv.addToFavorites(img);
    }
    
    public int getTuples(String table)
    {
        return imv.getNumberOfTuples(table);
    }

    public ImageDb getImageFromPath(String path) {
        return imv.requestImageFromPath(path);
    }

    public void alterPictureTable(ImageDb image) {
        imv.alterPictureTables(image);
    }
}